﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    using DAL.Entities;

    public class TaiKhoanDAL : BaseDAL, UTL.IBaseDAL 
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" SELECT *,(Case when vaitro = 1 then 'Admin' else 'User' end) as vt FROM taikhoan ";
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            string sql = @"DELETE FROM taikhoan WHERE taikhoan = '{0}'";
            sql = string.Format(sql,id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (taikhoan)obj;
            string sql = @"set dateformat mdy; INSERT INTO taikhoan(taikhoan,matkhau,hoten,vaitro) VALUES('{0}','{1}',N'{2}',{3}) ";
            sql = string.Format(sql,o.acc,o.pass,o.ten,o.vaitro);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (taikhoan)obj;
            string sql = @"set dateformat mdy; UPDATE taikhoan SET matkhau='{0}',hoten=N'{1}',vaitro={2} WHERE taikhoan='{3}' ";
            sql = string.Format(sql, o.pass,o.ten,o.vaitro,o.acc);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }



        public bool deleteobj(object obj)
        {
            throw new NotImplementedException();
        }
    }
}
